package com.caregiver.watch.business.user.model.dto;

import com.caregiver.watch.business.user.enums.CareRecipientWearingHabitEnum;
import com.caregiver.watch.business.user.enums.CareRelationshipEnum;
import com.caregiver.watch.business.user.model.po.UserCareRecipient;
import com.caregiver.watch.business.user.model.po.UserDevice;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDate;
import java.util.Optional;

/**
 * @Description: 添加亲友设备
 * @Author 疆戟
 * @Date 2025/8/24 21:13
 * @Version 1.0
 */
@Data
@Schema(description = "添加亲友设备")
public class AddContactDeviceParam {


    /**
     * 设备名称
     */
    @Schema(description = "设备名称")
    private String deviceName;

    /**
     * 设备UUId
     */
    @Schema(description = "设备UUId")
    private String deviceUuid;

    /**
     * 设备型号
     */
    @Schema(description = "设备型号")
    private String deviceModel;

    /**
     * 系统版本
     */
    @Schema(description = "系统版本")
    private String systemVersion;

    /**
     * 被照护人姓名
     */
    @Schema(description = "被照护人姓名")
    private String recipientName;

    /**
     * 与用户关系（本人、父亲、母亲、配偶等）
     */
    @Schema(description = "与用户关系（本人、父亲、母亲、配偶等）")
    private CareRelationshipEnum relationship;

    /**
     * 性别（0-未知 1-男 2-女）
     */
    @Schema(description = "性别（0-未知 1-男 2-女）")
    private Integer gender;

    /**
     * 生日
     */
    @Schema(description = "生日")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private LocalDate birthday;

    // 腕围
    @Schema(description = "腕围")
    private Integer wristCircumference;

    // 身高
    @Schema(description = "身高(cm)")
    private Integer height;

    // 体重
    @Schema(description = "体重(kg)")
    private Integer weight;

    /**
     * 佩戴习惯
     */
    @Schema(description = "佩戴习惯 UNKNOWN 未知 LEFT_HAND 左手 RIGHT_HAND 右手")
    private CareRecipientWearingHabitEnum wearingHabit;



    public UserCareRecipient buildUserCareRecipient(Long userId) {
        UserCareRecipient userCareRecipient = new UserCareRecipient();
        userCareRecipient.setUserId(userId);
        userCareRecipient.setName(this.recipientName);
        userCareRecipient.setRelationship(relationship.name());
        userCareRecipient.setGender(this.gender);
        userCareRecipient.setBirthday(this.birthday);
        userCareRecipient.setWristCircumference(this.wristCircumference);
        userCareRecipient.setHeight(this.height);
        userCareRecipient.setWeight(this.weight);
        userCareRecipient.setWearingHabit(Optional.ofNullable(this.wearingHabit).map(CareRecipientWearingHabitEnum::getCode).orElse(null));
        return userCareRecipient;
    }

    public UserDevice buildUserDevice(Long userId, Long recipientId) {
        UserDevice userDevice = new UserDevice();
        userDevice.setUserId(userId);
        userDevice.setDeviceUuid(this.deviceUuid);
        userDevice.setDeviceName(this.deviceName);
        userDevice.setDeviceModel(this.deviceModel);
        userDevice.setRecipientId(recipientId);
        return userDevice;
    }
}
